package org.example.order.controller;

import org.example.order.cache.OrderCacheList;
import org.example.order.domain.Order;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Description: HtmlContorller
 * Author: e
 * CreateDate: 2021-08-02
 */
@Controller
public class HtmlContorller {

    /**
     * 首页
     * @param map
     * @return
     */
    @RequestMapping("/index")
    public String index(ModelMap map) {
        map.addAttribute("commodity", "HUAWEI P50 Pro 麒麟4G 全网通 8GB+256GB（曜金黑）- 5999元");
        return "index";
    }

    /**
     * 订单列表
     * @param map
     * @return
     */
    @RequestMapping("/list")
    public String list(ModelMap map) {
        List<Order> orderList = new ArrayList<>();
        Map<Long, Order> orderMap = OrderCacheList.ORDER_MAP;
        for (Order order : orderMap.values()) {
            orderList.add(order);
        }
        map.addAttribute("orderList",orderList);
        return "list";
    }
}
